<?php
namespace app\shop\model;

use app\BaseModel;
use think\facade\Db;

class IndexCompany extends BaseModel
{
    //定义表名
    protected $name = 'longbing_card_company';


    protected static function init()
    {
        //TODO:初始化内容
    }
    /**
     * @param $uid
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 根据用户获取公司
     */
    public function companyInfo($uid,$uniacid){

        $dis['b.fans_id'] = $uid;
        $data = Db::name($this->name)
            ->alias('a')
            ->leftJoin('longbing_card_user_info b' ,'a.id = b.company_id')
            ->where($dis)
            ->field('a.*','b.fans_id')
            ->find();
        if(empty($data)){
            $data = Db::name($this->name)->where(['uniacid'=>$uniacid])->find();
        }
        return $data;
    }

    /**
     * @param $dis
     *
     * 获取公司
     */

    public function getCompany($dis){
        $data = $this->where($dis)->find();
        return !empty($data)?$data->toArray():'';
    }

    /**
     * User: chenniang
     * Date: 2019-09-29 10:23
     * @return void
     * descption:递归查找顶级公司图片|id
     */
    public function topCompany($id,$l=0,&$datas = []){
        $l++;
        $data = Db::name($this->name)->where(['id'=>$id])->field('desc,pid,id')->find();
        if(!empty($data)&&$l<20){
            $data = transImagesOne($data,['desc']);
            $datas['desc']  = $data['desc'];
            $datas['id']    = $data['id'];
            $this->topCompany($data['pid'],$l,$datas);
        }
        return $datas;
    }










}